package com.itholmes.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.itholmes.pojo.Emp;
import com.itholmes.utils.ConnectionsPool;
import com.itholmes.utils.JDBCUtils;

public class EmpDaoSelectOne {
	public Emp getOneSelect(int empno) {
		Emp emp = new Emp();
		Connection connection = JDBCUtils.getConnection();
		PreparedStatement pre = null;
		ResultSet rs = null;
		try {
			pre = connection.prepareStatement("select * from emp where empno = ?");
			pre.setInt(1, empno);
			
			rs = pre.executeQuery();
			while(rs.next()) {
				emp.setEmpno(rs.getInt("empno"));
				emp.setEname(rs.getString("ename"));
				emp.setJob(rs.getString("job"));
				emp.setMgr(rs.getInt("mgr"));
				emp.setHiredate(rs.getDate("hiredate"));
				emp.setSal(rs.getBigDecimal("sal"));
				emp.setCOMM(rs.getBigDecimal("COMM"));
				emp.setDeptno(rs.getInt("deptno"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		JDBCUtils.release(connection, pre, rs);
		//只要关闭了connection就要连接池中移除，不然会 报一个关闭后仍然运行的错误。
		ConnectionsPool.remove(connection);
		return emp;
	}
}
